Ubuntu Shell Scripts

#!/bin/bash at the head of file indicates shell type

  1. strict format

    For if [[ $input == "hello" ]], note that the space after [[ and before ]] is very strict, since [[]] can be used for matching regular expression

  2. arguments

    • $@: stores all the arguments in a list of string
    • $*: stores all the arguments as a single string
    • $#: stores the number of arguments
    • shift: remove the first argument

When starting login or interative shells, certain files will be executed based on the following tables:

For bash:
login-y interactive-y: profile
login-y interactive-n: profile
login-n interactive-y: bashrc

For zsh:
login-y interactive-y: zshenv zprofile zshrc zlogin
login-y interactive-n: zshenv zprofile zlogin
login-n interactive-y: zshenv zshrc
login-n interactive-n: zshenv